import java.time.LocalDate;

public class YearMonth {

    private int year;
    private int month;

    public YearMonth(int year, int month) {
        this.year = year;
        this.month = month;
    }

    public YearMonth(String date) {
        this(Integer.parseInt(date.substring(0, 4)), Integer.parseInt(date.substring(4, 6)));
    }

    public YearMonth(LocalDate date) {
        this(date.getYear(), date.getMonthValue());
    }

    public void previousMonth() {
        if(month == 1) {
            year--;
            month = 12;
        } else {
            month--;
        }
    }

    public void nextMonth() {
        if(month == 12) {
            year++;
            month = 1;
        } else {
            month++;
        }
    }

    public int getMonth() {
        return month;
    }

    public int getYear() {
        return year;
    }

}
